def 计算防御值(form):
    破甲设定 = {
        '元神破甲': [[0.2, 318], [0.2, 312]],
        '雪莲怒凋': [[0.1, 138], [0.05, 78]],
        '当阳怒吼': [[0.2, 318], [0.2, 312]],
        '虎虎生威': [[0.025, 48], [0.025, 42]]}
    断魂破甲设定 = [
        [[0.05, 84], [0.05, 78]],
        [[0.0625, 102], [0.0625, 96]],
        [[0.075, 126], [0.075, 114]],
        [[0.0875, 144], [0.0875, 132]],
        [[0.1, 162], [0.1, 156]]
    ]
    铜台破甲设定 = [
        [[0.05, 84], [0.05, 78]],
        [[0.06, 108], [0.06, 102]]
    ]
    八阵图青龙破甲设定 = [
        [[0.005, 6], [0.005, 6]],
        [[0.01, 12], [0.01, 12]],
        [[0.015, 24], [0.015, 24]],
        [[0.02, 30], [0.02, 30]],
        [[0.025, 36], [0.025, 36]],
        [[0.03, 48], [0.03, 48]]
    ]
    天狼爪破甲设定 = [
        [[[0.01, 12], [0.01, 12]], [[0.015, 24], [0.015, 24]], [[0.02, 30], [0.02, 30]]],
        [[[0.02, 30], [0.02, 30]], [[0.03, 48], [0.03, 48]], [[0.04, 60], [0.04, 60]]],
        [[[0.03, 48], [0.03, 48]], [[0.045, 72], [0.045, 72]], [[0.06, 96], [0.06, 96]]],
        [[[0.04, 60], [0.04, 60]], [[0.06, 96], [0.06, 96]], [[0.08, 126], [0.08, 126]]],
        [[[0.05, 78], [0.05, 78]], [[0.075, 120], [0.075, 120]], [[0.1, 162], [0.1, 162]]]
    ]
    韧性减破设定 = [
        [[0, 0], [0, 0]],
        [[0.01, 12], [0.01, 12]],
        [[0.011, 12], [0.011, 12]],
        [[0.012, 18], [0.012, 18]],
        [[0.013, 18], [0.013, 18]],
        [[0.014, 18], [0.014, 18]],   # 5
        [[0.015, 18], [0.015, 18]],
        [[0.016, 24], [0.016, 24]],
        [[0.017, 24], [0.017, 24]],
        [[0.018, 24], [0.018, 24]],
        [[0.019, 24], [0.019, 24]],   # 10
        [[0.020, 30], [0.020, 30]],
        [[0.021, 30], [0.021, 30]],
        [[0.022, 30], [0.022, 30]],
        [[0.023, 30], [0.023, 30]],
        [[0.024, 36], [0.024, 36]],   # 15
        [[0.025, 36], [0.025, 36]],
        [[0.026, 36], [0.026, 36]],
        [[0.027, 42], [0.027, 42]],
        [[0.028, 42], [0.028, 42]],
        [[0.029, 42], [0.029, 42]],   # 20
        [[0.030, 42], [0.030, 42]],
        [[0.031, 48], [0.031, 48]],
        [[0.032, 48], [0.032, 48]],
        [[0.033, 48], [0.033, 48]],
        [[0.034, 48], [0.034, 48]],   # 25
        [[0.035, 54], [0.035, 54]],
        [[0.036, 54], [0.036, 54]],
        [[0.037, 54], [0.037, 54]],
        [[0.038, 54], [0.038, 54]],
        [[0.039, 60], [0.039, 60]],   # 30
        [[0.040, 60], [0.040, 60]],
        [[0.041, 60], [0.041, 60]],
        [[0.042, 60], [0.042, 60]],
        [[0.043, 66], [0.043, 66]],
        [[0.044, 66], [0.044, 66]],   # 35
        [[0.045, 66], [0.045, 66]],
        [[0.046, 66], [0.046, 66]],
        [[0.047, 72], [0.047, 72]],
        [[0.048, 72], [0.048, 72]],
        [[0.049, 72], [0.049, 72]],   # 40
        [[0.050, 78], [0.050, 78]],
        [[0.051, 78], [0.051, 78]],
        [[0.052, 78], [0.052, 78]],
        [[0.053, 78], [0.053, 78]],
        [[0.054, 84], [0.054, 84]],   # 45
        [[0.055, 84], [0.055, 84]],
        [[0.056, 84], [0.056, 84]],
        [[0.057, 84], [0.057, 84]],
        [[0.058, 90], [0.058, 90]],
        [[0.060, 90], [0.060, 90]]
    ]
    夫妻减破设定 = [
        [[0.1, 156], [0.1, 156]],
        [[0.11, 168], [0.11, 168]],
        [[0.12, 186], [0.12, 186]],
        [[0.13, 198], [0.13, 198]],
        [[0.14, 216], [0.14, 216]],
        [[0.15, 234], [0.15, 234]]
    ]

    if '断魂' in form:
        破甲设定['断魂'] = 断魂破甲设定[int(form['断魂等级'])]
    if '铜台锁梦' in form:
        破甲设定['铜台锁梦'] = 铜台破甲设定[int(form['铜台锁梦阶层']) - 9]
    if '八阵图青龙破甲' in form:
        破甲设定['八阵图青龙破甲'] = 八阵图青龙破甲设定[int(form['八阵图青龙破甲阶层']) - 1]
    if '天狼爪' in form:
        破甲设定['天狼爪'] = 天狼爪破甲设定[int(form['天狼爪等级']) - 1][int(form['天狼爪连球数']) - 1]

    总物防 = int(form['总物防'])
    总法防 = int(form['总法防'])
    元神物防 = int(form['元神物防'])
    元神法防 = int(form['元神法防'])
    八阵图物防 = int(form['八阵图物防'])
    八阵图法防 = int(form['八阵图法防'])

    减破百分比 = 0
    if '奥义护体之神' in form:
        减破百分比 += int(form['奥义护体之神减破百分比']) * 0.01
    if '子女藤甲' in form:
        减破百分比 += float(form['子女藤甲减破百分比']) * 0.01
    if '坚韧之灵' in form:
        减破百分比 += int(form['坚韧之灵减破百分比']) * 0.01

    韧性值 = int(form['韧性'])
    夫妻等级 = int(form['夫妻等级'])

    物防破甲值 = 0
    法防破甲值 = 0
    result = {}

    for 破甲状态 in 破甲设定:
        if 破甲状态 in form:
            物防破甲值 += min((round((总物防 - 元神物防 - 八阵图物防) / 6 * (破甲设定[破甲状态][0][0]) * (1 - 减破百分比)) * 6,
                          破甲设定[破甲状态][0][1]))
            法防破甲值 += min((round((总法防 - 元神法防 - 八阵图法防) / 6 * (破甲设定[破甲状态][1][0]) * (1 - 减破百分比)) * 6,
                          破甲设定[破甲状态][1][1]))
    # print(f'物防破甲值: {物防破甲值}')
    # print(f'法防破甲值: {法防破甲值}')

    物防韧性减破值 = min((round((总物防 - 元神物防 - 八阵图物防) / 6 * 韧性减破设定[韧性值][0][0]) * 6, 韧性减破设定[韧性值][0][1]))
    法防韧性减破值 = min((round((总法防 - 元神法防 - 八阵图法防) / 6 * 韧性减破设定[韧性值][1][0]) * 6, 韧性减破设定[韧性值][1][1]))
    物防破甲值 -= min((物防韧性减破值, 物防破甲值))
    法防破甲值 -= min((法防韧性减破值, 法防破甲值))
    # print(f'物防韧性减破值: {物防韧性减破值}')
    # print(f'法防韧性减破值: {法防韧性减破值}')

    # print(f'最终物防(无夫妻减破状态): {总物防 - 物防破甲值}')
    # print(f'最终法防(无夫妻减破状态): {总法防 - 法防破甲值}')

    result['最终物防(无夫妻减破状态)'] = 总物防 - 物防破甲值
    result['最终法防(无夫妻减破状态)'] = 总法防 - 法防破甲值

    物防夫妻减破值 = min((
        round((总物防 - 元神物防 - 八阵图物防) / 6 * 夫妻减破设定[夫妻等级 - 15][0][0] * (1 - 减破百分比)) * 6, 夫妻减破设定[夫妻等级 - 15][0][1]))
    法防夫妻减破值 = min((
        round((总法防 - 元神法防 - 八阵图法防) / 6 * 夫妻减破设定[夫妻等级 - 15][1][0] * (1 - 减破百分比)) * 6, 夫妻减破设定[夫妻等级 - 15][1][1]))
    物防破甲值 -= min((物防夫妻减破值, 物防破甲值))
    法防破甲值 -= min((法防夫妻减破值, 法防破甲值))
    # print(f'物防夫妻减破值: {物防夫妻减破值}')
    # print(f'法防夫妻减破值: {法防夫妻减破值}')

    # print(f'最终物防(有夫妻减破状态): {总物防 - 物防破甲值}')
    # print(f'最终法防(有夫妻减破状态): {总法防 - 法防破甲值}')

    result['最终物防(有夫妻减破状态)'] = 总物防 - 物防破甲值
    result['最终法防(有夫妻减破状态)'] = 总法防 - 法防破甲值

    return result
